<html>
<head>
<title>TableFilter - Java 5 support</title>
<link rel="stylesheet" type="text/css" href="tablefilter.css">
</head>
<body><div id='content'>

  <h1>Usage with Java 5</h1>
  
    <p>
      This library was initially developed targeting Java 5, and then modified 
      to handle the new filtering capabilities in Java 6. Both versions were 
      very different, but considering that the features in Java 6 will likely 
      stay, I decided to retrofit the new implementation into the Java 5 ' 
      library, adding some classes that only exist on the Java 6 standard 
      library. These added classes are placed in the 
      <a href='api5/net/coderazzi/filters/artifacts/package-summary.html'>net.coderazzi.filters.artifacts</a>
      package (only for the Java 5 implementation).
    </p>
    
    <p>
      At the end, both versions share most of the code, although the internal 
      imports are different in some cases. And users see mostly the 
      <b>same interface</b> using Java 5 or Java 6, which is an important 
      feature, in case some later migration happens. Specific exceptions exist; for example,
      autoselection or adaptive choices are only available on the Java 6 version.
    </p>

    <p>
      There is, however, a difference between 
      <a href='http://java.sun.com/javase/6/docs/api/javax/swing/JTable.html?is-external=true'>JTable</a>
      users in Java 5 and Java 6: the former does not provide sorting 
      capabilities. The solution is usually  to setup a table model with 
      sorting capabilities, like the 
      <a href='http://www.devdaily.com/java/jwarehouse/hsqldb/src/org/hsqldb/util/TableSorter.java.shtml'>TableSorter</a>. 
      The source version of <span class='mark'>TableFilter</span> includes 
      such class for the test programs, although the 
      <span class='mark'>TableFilter</span> 
      itself does obviously not require it.
    </p>
    
    <p>
      Although this library exports the same interface to Java 5 and 6 users, 
      the internal implementation is quite different; in Java 6, there is one 
      table model, while in Java 5 users must handle at least 
      two table models (plus a third one if sorting is also added):
      <ul>
        <li>The normal table model associated initially to the table.</li>
        <li>A model providing the filtering capabilities.</li>
      </ul>
    </p>
    
    <p>
      This library is distributed with an implementation of the second model, 
      described below, and it can be setup automatically; note, however, that 
      the usage of multiple table models makes some operations more 
      complicated. For example, once that filtering is on place, the row number 
      in the view does not correspond any more to the row number in the model; the
      <a href='http://java.sun.com/javase/6/docs/api/javax/swing/JTable.html?is-external=true'>JTable</a>
      provides 
      <a href='http://java.sun.com/javase/6/docs/api/javax/swing/JTable.html#convertColumnIndexToModel(int)'>methods</a> 
      to enquiry for translations between both views, but in version 5, users 
      must extract the model and perform these queries against the model.
    </p>
    
    <p>
      In practical terms, this means that the user must perform multiple model conversions;
      for example, the provided <a href='index.html#examples'>example</a> includes the following
      code to obtain the selected row element:      
    </p>
    
    <pre>int selected = table.getSelectedRow();
if (selected != -1) {
  int model = ((TableModelFilter) table.getModel()).convertRowIndexToModel(selected);
  Object selection = tableModel.getRow(tableSorter.modelIndex(model));
}</pre>
    
    <p>
    	Note that from version 5.0.0, it is not released anymore the Java 5 version 
    	(Java 5 entered its end-of-life on April 8, 2008 and is 
    	no longer supported as of November 3, 2009). The last release including
    	the Java 5 compatible version is numbered 4.5.0 (17th November 2012).
    </p>

    
    <h2>ITableModelFilter</h2>

      <p>
        Java 5 users of this library must attach, to the table, a model 
        implementing the interface
        <a href='api5/net/coderazzi/filters/artifacts/ITableModelFilter.html'>ITableModelFilter</a>
      </p>

      <p>
        If the attached model does not implement this interface, the library 
        automatically creates one and replaces the current model with it. The 
        default implementation is called
        <a href='api5/net/coderazzi/filters/artifacts/TableModelFilter.html'>TableModelFilter</a>.
      </p>

      <p>
        This implementation tries to mimic the behaviour found in the Java 6 
        tables; however, users can definitely provide their own implementation, 
        for performance or extended interface reasons. The  implementation 
        provides two specific methods to convert positions between the index 
        and the model:
        <ul>
          <li>
            <a href='api5/net/coderazzi/filters/artifacts/TableModelFilter.html#convertRowIndexToModel(int)'>convertRowIndexToModel</a>
            returns the location of index in terms of the underlying model.</li>
          <li>
            <a href='api5/net/coderazzi/filters/artifacts/TableModelFilter.html#convertRowIndexToView(int)'>convertRowIndexToView</a>
            returns the location of index in terms of the view.</li>
        </ul>
      </p>

 
</div></body>
</html>
